Skip to content

fix(chart): wire chart-styles CSS so custom tooltips are actually visible#17

Merged
Shewart merged 6 commits into
mainfrom
fix/chart-tooltip-css
Jun 18, 2026
Merged

fix(chart): wire chart-styles CSS so custom tooltips are actually visible#17
Shewart merged 6 commits into
mainfrom
fix/chart-tooltip-css

Conversation

@Shewart

@Shewart Shewart commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Summary

After shellui add chart, hovering any chart point showed an invisible tooltip — values appeared white-on-white because the custom HTML emitted by ApexCharts referenced .custom-tooltip-* classes that nothing styled. The CSS to style them already existed in ChartStylesTemplate but was three different kinds of broken: not registered in ComponentRegistry, not declared as a dependency of chart, and configured with a FilePath that would have written the file into Components/UI/wwwroot/css/ (unreachable by the browser) instead of project-root wwwroot/css/.

This PR makes shellui add chart deliver the CSS that already existed, and auto-wires the <link> tag into the host so the user doesn't have to edit App.razor by hand.

Changes

Wire chart-styles end-to-end

  • src/ShellUI.Templates/Templates/ChartStylesTemplate.csFilePath changed from wwwroot/css/charts.css (which got combined with Components/UI/ for a broken final path) to ../../wwwroot/css/charts.css. Same path-traversal trick the existing shellui-js template already uses to escape the component tree.
  • src/ShellUI.Templates/Templates/ChartTemplate.cschart-styles added to Dependencies alongside chart-variants. Every chart-family component transitively depends on chart, so they all pick up the CSS through the recursive walk.
  • src/ShellUI.Templates/ComponentRegistry.cschart-styles registered in both the metadata dictionary and the GetComponentContent switch. Same orphan class as data-table-models in branch 4 — file existed on disk, never reachable via the CLI.

Auto-link stylesheets in the host

  • src/ShellUI.CLI/Services/InitService.cs — new InjectStylesheetLink(content, href) and InjectStylesheetIntoHostAsync(href) helpers. Patches Components/App.razor (Blazor Web App / Server / SSR) or wwwroot/index.html (WASM standalone), idempotently. Lives alongside the existing RewriteAppRazor / RewriteWasmIndexHtml helpers from branch 3 — same patterns, same testing approach.
  • src/ShellUI.CLI/Services/ComponentInstaller.cs — after InstallComponents finishes installing source files and NuGet deps, it walks the installed set, calls ResolveHostStylesheetHref on each FilePath, and injects <link> tags for any CSS asset that lives under ../../wwwroot/. Generic by design — any future asset CSS template gets the same treatment automatically, no per-component special case.

Out of scope (deferred)

Per discussion: the "ApexCharts chrome restyle" (replacing default legend/axis text styling with Tailwind-classed equivalents) is a future branch. This PR ships only the CSS that makes the custom tooltip readable — Fix 13 in the notes — which was the alpha.4 blocker. The shadcn-quality restyle stays on the roadmap.

Tests (10 new)

ShellUI.Tests/ChartStylesTests.cs:

Registry wiring:

  • chart-styles is registered and IsAvailable = false
  • chart depends on chart-styles
  • chart-styles.FilePath starts with ../../wwwroot/ and ends with .css
  • Content covers all six .custom-tooltip-* classes, the key .apexcharts-* classes (apexcharts-tooltip, apexcharts-legend, apexcharts-xaxis-label), and is theme-aware (uses var(--popover), var(--foreground), var(--border))

Link injector:

  • ResolveHostStylesheetHref strips ../../wwwroot/ from a CSS asset path
  • Returns null for non-CSS file paths and for non-wwwroot CSS paths
  • Returns null for ../../wwwroot/shellui.js (script, not stylesheet)
  • InjectStylesheetLink places the tag inside <head> (positionally verified)
  • InjectStylesheetLink is idempotent — running twice produces identical output
  • Supports multiple distinct hrefs without overwriting earlier injections

CI

.github/workflows/ci.yml smoke step:

  • test -f wwwroot/css/charts.css — the CSS file actually landed
  • grep -q '<link href="css/charts.css"' Components/App.razor — App.razor was patched

Verification

  • dotnet test ShellUI.Tests53/53 passing (10 new + 43 from previous branches)
  • dotnet build src/ShellUI.CLI — clean

Test plan

  • CI green (tests + smoke-step CSS + link assertions)
  • Manual: scaffold a fresh dotnet new blazor → install the prerelease CLI tool → shellui initshellui add chartdotnet build succeeds. Check that wwwroot/css/charts.css exists and Components/App.razor has <link href="css/charts.css" rel="stylesheet" /> in <head>. Visit a page rendering a <Chart> and confirm the tooltip is readable (theme-aware popover background, foreground text, no more white-on-white)
  • Manual: run shellui add chart a second time — confirm the link tag isn't double-injected (idempotency)
  • Manual: in WASM project, confirm wwwroot/index.html is patched instead of App.razor

Shewart added 6 commits June 18, 2026 11:21
Enhanced the CI workflow to verify the presence of chart-styles CSS and ensure it is correctly linked in App.razor. This prevents issues with invisible text on chart hover and improves the robustness of the installation process.
…yles dependency

Adjusted the file path in ChartStylesTemplate to correctly reference the CSS file location. Additionally, updated the ChartTemplate to include "chart-styles" in its dependencies, ensuring proper integration of chart styles within the ShellUI theme system.
…unctionality

Introduced comprehensive unit tests for the ChartStylesRegistry and StylesheetInjection classes. The tests validate the registration and dependencies of chart styles, ensure correct file path targeting, and verify the functionality of stylesheet injection methods, enhancing overall test coverage and reliability of the ShellUI component system.
Enhanced the ComponentInstaller to automatically wire installed stylesheets from wwwroot into the host, eliminating the need for manual <link> tag additions. Introduced a new method, ResolveHostStylesheetHref, to determine the correct href for stylesheets, streamlining the integration of CSS assets into the ShellUI component system.
Updated the ComponentRegistry to include the "chart-styles" component, enhancing the template system by ensuring it is registered and its content is accessible. This addition supports improved styling options for charts within the ShellUI framework.
Added methods to inject stylesheet links into the host files (App.razor and index.html) for newly installed components, streamlining the integration of CSS assets. This enhancement automates the process of linking stylesheets, improving user experience by eliminating the need for manual edits after installation.
@Shewart Shewart merged commit b0350ec into main Jun 18, 2026
1 check passed
@Shewart Shewart deleted the fix/chart-tooltip-css branch June 18, 2026 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant